<?php

class CarForm extends BaseCarForm {
	protected $parentId = null;

	public function configure() {
		unset($this['tree_left'], $this['tree_right'], $this['tree_parent']);

		$c = new Criteria;
		$c->addAscendingOrderByColumn(CarPeer::SCOPE);
		$c->addAscendingOrderByColumn(CarPeer::TREE_LEFT);

		$this->widgetSchema['parent_id'] = new sfWidgetFormPropelChoice(
			array('model' => 'Car',
					'criteria'=>$c,
					'method' => 'getIndentedName'
			)
		);

		$this->setDefault('parent_id', $this->object->getParentId());
		$this->widgetSchema->setLabel('parent_id', 'Child of');
	}

// сохранили предыдущее значение
	public function updateParentIdColumn($parentId) {
		$this->parentId = $parentId;
	}

	protected function doSave($con = null) {
		parent::doSave($con);

		if ($this->parentId != $this->object->getParentId()) {
			$parent = CarPeer::retrieveByPK($this->parentId);
			CarPeer::moveToLastChildOf($parent, $this->object);			
		}
	}
}